home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
1_0-2
/
D2R_FOLD
/
D2R_OPEN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1986-11-06
|
1KB
|
45 lines
#include "D2R globals.h"
open()
{
/* IO packet */
Str255 filename;
int vrefnum,
refnum,
errcode;
int currVol;
OSErr err;
if(GetFile(NULL,filename,&vrefnum))
{
/* Empty buffer */
if (GetHandleSize(RezH) != NULL)
DisposHandle(RezH);
/* GetVol(NULL,&currVol);
SetVol(NULL,vrefnum); */
if ((err = FSOpen(filename,vrefnum,&refnum)) != noErr)
ErrorAlert("\pSorry - can't open that file!");
/* SetVol(NULL,currVol); */
/* get size of the file */
GetEOF(refnum, &count);
/* allocate buffer */
RezH = (Handle) NewHandle(count);
if (RezH == NULL)
{
/* not enough room: close channel */
myError(OutOfMemErr);
/* and exit */
return(false);
}
HLock(RezH); /* NEVER dereference a floating handle!! */
if ((errcode = FSRead(refnum,&count,*RezH)) != noErr)
ErrorAlert("\pSorry - can't read that file!");
HUnlock(RezH);
err = FSClose(refnum);
EnableItem(mymenu[file_menu],igetinfo);
EnableItem(mymenu[file_menu],iwrite);
strcpy(RezName,filename);
}
}